﻿//------------------------------------------------------------------------------
// <copyright file="ControllerBase.cs" company="David Martos">
//     Copyright (c) David Martos.  All rights reserved.
// </copyright>
// <summary>Base class for all controllers</summary>
//  ----------------------------------------------------------------------------
namespace Dissemination.MVC.Controllers
{
    using System.Web.Mvc;
    using log4net;

    /// <summary>
    /// Base class for all controllers
    /// </summary>
    public class ControllerBase : Controller
    {
        /// <summary>
        /// Logger to log errors and evengs
        /// </summary>
        protected static readonly ILog log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

        /// <summary>
        /// Method called when an exception occurs
        /// </summary>
        /// <param name="filterContext">Filter context</param>
        protected override void OnException(ExceptionContext filterContext)
        {
            filterContext.ExceptionHandled = true;
            if (log.IsErrorEnabled) log.ErrorFormat("Error captured by the ControllerBase", filterContext.Exception);
            this.View("Error", filterContext.Exception).ExecuteResult(this.ControllerContext);
        }
    }
}